package com.ruoyi.web.controller.booksReviews;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.reviews.domain.BookReviews;
import com.ruoyi.reviews.service.IBookReviewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 书籍评论Controller
 * 
 * @author 张队
 * @date 2025-05-11
 */
@RestController
@RequestMapping("/reviews/reviews")
public class BookReviewsController extends BaseController
{
    @Autowired
    private IBookReviewsService bookReviewsService;

    /**
     * 查询书籍评论列表
     */
    @PreAuthorize("@ss.hasPermi('reviews:reviews:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookReviews bookReviews)
    {
        startPage();
        List<BookReviews> list = bookReviewsService.selectBookReviewsList(bookReviews);
        return getDataTable(list);
    }

    /**
     * 导出书籍评论列表
     */
    @PreAuthorize("@ss.hasPermi('reviews:reviews:export')")
    @Log(title = "书籍评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookReviews bookReviews)
    {
        List<BookReviews> list = bookReviewsService.selectBookReviewsList(bookReviews);
        ExcelUtil<BookReviews> util = new ExcelUtil<BookReviews>(BookReviews.class);
        util.exportExcel(response, list, "书籍评论数据");
    }

    /**
     * 获取书籍评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('reviews:reviews:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookReviewsService.selectBookReviewsById(id));
    }

    /**
     * 新增书籍评论
     */
    @PreAuthorize("@ss.hasPermi('reviews:reviews:add')")
    @Log(title = "书籍评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookReviews bookReviews)
    {
        return toAjax(bookReviewsService.insertBookReviews(bookReviews));
    }

    /**
     * 修改书籍评论
     */
    @PreAuthorize("@ss.hasPermi('reviews:reviews:edit')")
    @Log(title = "书籍评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookReviews bookReviews)
    {
        return toAjax(bookReviewsService.updateBookReviews(bookReviews));
    }

    /**
     * 删除书籍评论
     */
    @PreAuthorize("@ss.hasPermi('reviews:reviews:remove')")
    @Log(title = "书籍评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookReviewsService.deleteBookReviewsByIds(ids));
    }
}
